package com.guanzhi.mp.controller;

import com.guanzhi.mp.api.AjaxResult;
import com.guanzhi.mp.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Mybatis-Plus 练习
 * <p> Package: com.guanzhi.mp.controller </p>
 * <p> File: UserController.java </p>
 * <p> Description:  (用户 RestFul API)</p>
 * <p> Date: 2024/6/16 14:55</p>
 *
 * @author 观之
 * @version 1.0 （代码版本）
 * @email <a href="mailto:guanzhi55634@aliyun.com">观之</a>（邮箱）
 * @date 2024/6/16 14:55
 * @since jdk17（jdk版本）
 */
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @GetMapping("/logic")
    public AjaxResult logicDelete() {
        userService.logicDelete();
        return AjaxResult.success();
    }


    @GetMapping("/all")
    public AjaxResult getAll() {
        return AjaxResult.success(userService.getAll());
    }

    @GetMapping("/add")
    public AjaxResult addUser(){
        userService.addUser();
        return AjaxResult.success();
    }

    @GetMapping("/page/{pageNum}/{pageSize}")
    private AjaxResult getUserPage(@PathVariable Integer pageNum,@PathVariable Integer pageSize) {
        return AjaxResult.success(userService.getUserByPage(pageNum, pageSize));
    }
}
